package com.xc.freeapp.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.xc.freeapp.dao.TakemedicDao;
import com.xc.freeapp.dao.TimingvisitDao;
import com.xc.freeapp.dao.VaccineDao;
import com.xc.freeapp.dao.VaccinepersonDao;
import com.xc.freeapp.dao.dataSource.DBContextHolder;
import com.xc.freeapp.entity.Takemedic;
import com.xc.freeapp.service.TakemedicService;

/**
 * 
 * @author wukailuo
 *
 */
@Service
public class TakemedicServiceImpl implements TakemedicService {
	
	Logger log = Logger.getLogger(this.getClass());
	@Autowired
	private  TakemedicDao  takemedicdao;
	@Autowired
	private  TimingvisitDao   timingvisitdao;
	@Autowired
	private  VaccinepersonDao    vaccinepersonDao; 
	
	
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public Map<String,Object> getremindamount(String usersid) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		log.info("备忘录统计");
		int userid=Integer.parseInt(usersid);
		//根据用户id查找用户定时吃药记录总数
		int  Takemedic=takemedicdao.getremindamount(userid);
		//根据用户id查找用户定时复诊记录总数
		int  Timingvisit=timingvisitdao.getremindamount(userid);
		//根据用户id查找用户疫苗提醒记录总数
		int  vaccine=vaccinepersonDao.selectCount(userid);
		Map<String, Object>   map=new  HashMap<String, Object>();
		 map.put("takemediccount",Takemedic);
		 map.put("timingvisit", Timingvisit);
		 map.put("vaccinecount", vaccine);
		return map;
	}
	
	@Transactional(propagation = Propagation.REQUIRED, readOnly = true)
	public List<Takemedic> gettakemediclist(String userid,	PageBounds pageBounds) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		return takemedicdao.getTakeMedicList(userid,pageBounds);
	}
   
	public int inserttakemedic(Takemedic takemedic) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		return takemedicdao.inserttakemedic(takemedic);
	}
  
	public int updatetakemedic(Takemedic takemedic) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		return takemedicdao.updatetakemedic(takemedic);
	}
 
	public Takemedic gettakemedic(int id) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		return takemedicdao.gettakemedic(id);
	}

	public int deletetakemedic(String id) {
		DBContextHolder.switchDataSourceRW();//切换数据源
		return takemedicdao.deletetakemedic(id);
	}

}
